package com.wsj.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.wsj.dao.IHomeSiteAdBannerDao;
import com.wsj.service.IHomeSiteAdBannerServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.page.PageResultSet;
import com.wsj.web.vo.homeSite.HomeSiteAdBanner;

public class HomeSiteAdBannerServImpl implements IHomeSiteAdBannerServ {

	private IHomeSiteAdBannerDao homeSiteAdBannerDao; 
	
	public void add(HomeSiteAdBanner hs) throws BusinessException {
		if(hs!=null){
			this.homeSiteAdBannerDao.add(hs);
			hs.setSequence(hs.getId());
			this.homeSiteAdBannerDao.update(hs);
		}
	}

	public void delete(HomeSiteAdBanner hs) throws BusinessException {
		if(hs!=null){
			this.homeSiteAdBannerDao.delete(hs);
		}
	}

	public List loadByDiscriptId(Integer discriptId) throws BusinessException {
		List list = new ArrayList();
		if(discriptId != null && !discriptId.equals(0)){
			list = this.loadByDiscriptId(discriptId);
		}
		
		return list;
	}

	public List loadByNewsClassId(Long newsClassId) throws BusinessException {
		List list = new ArrayList();
		list = this.homeSiteAdBannerDao.loadByNewsClassId(newsClassId);
		return list;
	}

	public HomeSiteAdBanner loadHsAdBannerById(Integer id) throws BusinessException {
		HomeSiteAdBanner hs = new HomeSiteAdBanner();
		if(id != null && !id.equals(0)){
			hs = this.homeSiteAdBannerDao.loadHsAdBannerById(id);
		}
		return hs;
	}

	public void update(HomeSiteAdBanner hs) throws BusinessException {
		if(hs!=null){
			this.homeSiteAdBannerDao.update(hs);
		}
	}


	public IHomeSiteAdBannerDao getHomeSiteAdBannerDao() {
		return homeSiteAdBannerDao;
	}

	public void setHomeSiteAdBannerDao(IHomeSiteAdBannerDao homeSiteAdBannerDao) {
		this.homeSiteAdBannerDao = homeSiteAdBannerDao;
	}

	public PageResultSet loadPageList(Long newsClassId,Integer hsDesId,String title, Integer isImg, Short isLink, Short isJs, Integer page,Integer pageSize) throws BusinessException {
		return this.homeSiteAdBannerDao.loadPageList(newsClassId,hsDesId,title, isImg, isLink, isJs, page,pageSize);
	}

	public List loadTopByNewsClassId(long newsClassId, int top) throws BusinessException {
		
		List list=this.homeSiteAdBannerDao.loadTopByNewsClassId(newsClassId, top);
		
		return list;
	}

	public List loadTopByOnlyNewsClassId(long newsClassId, int top) throws BusinessException {
		List list=this.homeSiteAdBannerDao.loadTopByOnlyNewsClassId(newsClassId,top);
		return list;
	}

	/**
	 * 首页：根据是否是图片各去前 top 条广告
	 * */
	public List loadTopByDesId(Integer desId,Integer isPic, Integer top) throws BusinessException {
		return this.homeSiteAdBannerDao.loadTopByNewsClassId(desId,isPic, top);
	}

	/*****
	 * 通过广告分类名,广告描述名,图片还是文字,是否删除,前几个 ,查询广告列表
	 */
	public List loadHomeSiteAdBannerByClassName(String newsClassName, String homeSiteAdBannerName,Short picOrletter, Short isdel, Integer top) throws BusinessException 
	{
		return this.getHomeSiteAdBannerDao().loadHomeSiteAdBannerByClassNameDao(newsClassName,  homeSiteAdBannerName, picOrletter,  isdel,  top);
	}

	/**  
	 * 参数：广告源ID、广告描述ID、类型，向上或向下
	 * */
	public Boolean updateSequence(Integer adId, Integer adDesId, Integer typeId) throws BusinessException {
		Boolean flg = this.homeSiteAdBannerDao.updateSequence(adId, adDesId, typeId);
		return flg;
	}

}
